﻿using System.IO.Ports;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Zhy.ModbusNET.Test
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 获取可用的COM端口字符串数组
            string[] ports = SerialPort.GetPortNames();

            foreach (string port in ports)
            {
                comPort.Items.Add(port);
            }
        }

        /// <summary>
        /// 连接按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            // 获取按钮的名称
            var btnContent = btnConnect.Content;
            // 判断是断开还是连接
            if (object.Equals(btnContent, "连接"))
            {
                //modbusRTU = new ModbusRTU(comPort.Text);
                //modbusRTU.Connect();
                // 修改按钮的显示字符串
                btnConnect.Content = "断开";
                // 修改LED灯颜色
                //LED.Background = Color.LimeGreen;
            }
            else // 执行断开连接的操作
            {

                // 关闭控制器连接
                //modbusRTU?.Disconnect();
                // 修改按钮的显示字符串
                btnConnect.Content = "连接";
                // 修改LED灯颜色
                //LED.BackColor = Color.Gray;
            }
        }

        

        /// <summary>
        /// 读取寄存器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetRegister_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 写入单个寄存器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnWriteSingleRegisters_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 写入多个寄存器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnWriteMultiRegisters_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 获取线圈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetCoil_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 写入单个线圈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnWriteSingleCoil_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 写入多个线圈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnWriteMultiCoil_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}